package com.shop.shopserver.controller.user;

import com.shop.shopcommon.context.SecurityContext;
import com.shop.shopserver.AopTest;
import com.shop.shopserver.annotation.RequestKeyParam;
import com.shop.shopserver.annotation.RequestLock;
import com.shop.shopserver.filter.HierarchicalBloomFilter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class TestController {
    @Autowired
    private HierarchicalBloomFilter hierarchicalBloomFilter;
    @GetMapping("/test")
    public String test(String id) {
        System.out.println("test "+hierarchicalBloomFilter.contains(id));
        return "test";
    }
    @RequestLock(prefix = "testaop")
    @PostMapping("/testaop")
    public String testaop(@RequestBody AopTest aopTest) {
        System.out.println(aopTest);
        return "testaop";
    }

    @GetMapping("/testGetId")
    public String testGetId() {
        Authentication mainThreadAuth = SecurityContextHolder.getContext().getAuthentication();
        log.info("主线程中的 Authentication: {}", mainThreadAuth);
        System.out.println("test "+ SecurityContext.getUserId());
        return "test";
    }
}
